package 字符串;

/**
 * @Author Weton Li
 * @Date 2021/4/3 20:33
 */
public class 反转字符串元音字母 {
    public static String method(String s){

        if (s == null || s.length() == 0) {
            return s;
        }
        String vowels = "aeiouAEIOU";

        // 将字符串转化成char类型数组
        char[] chars = s.toCharArray();
        int start = 0;
        int end = s.length() - 1;
        while (start < end) {
            // 双指针相向而行找元音字符
            while (start < end && !vowels.contains(chars[start] + "")) {
                start++;
            }
            while (start < end && !vowels.contains(chars[end] + "")) {
                end--;
            }
            swap(chars, start, end);
            start++;
            end--;
        }
        return new String(chars);


    }
    public static void swap(char[] chars, int start, int end) {
        char temp = chars[start];
        chars[start] = chars[end];
        chars[end] = temp;
    }


    public static void main(String[] args) {
        String input = "hello";
        System.out.println(method(input));
    }
}
